package cn.supermaster.management.web.service.system.impl;

import cn.supermaster.management.common.page.TableDataInfo;
import cn.supermaster.management.common.response.WebResponse;
import cn.supermaster.management.common.utils.ShiroUtils;
import cn.supermaster.management.common.utils.WebHelper;
import cn.supermaster.management.system.domain.SystemNotice;
import cn.supermaster.management.system.service.ISystemNoticeService;
import cn.supermaster.management.web.service.system.ISNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import java.util.List;

/**
 * All rights Reserved, Designed By www.super-bytecode.com
 *
 * @ProjectName: supermaster-management
 * @Package: cn.supermaster.management.web.service.system.impl
 * @ClassName: SNoticeServiceImpl
 * @Description: []
 * <p> </p>
 * @Author: [Lance Ting]
 * @Date: 2021/2/19 19:44
 * @Version: V1.0
 * @Copyright: 2021 www.super-bytecode.com Inc. All rights reserved.
 * TODO: 注意,本文件Lance Ting所作,如果转载或使用请标明具体出处!
 **/
@Service
public class SNoticeServiceImpl implements ISNoticeService {
    private String prefix = "system/notice";

    @Autowired
    private ISystemNoticeService systemNoticeService;

    /*
     * ================================================
     *  页面跳转功能实现
     * ================================================
     */

    /**
     * @Description: []
     * <p></P>
     * @Title: skipNoticeIndexHtml
     * @Author: Lance Ting
     * @Date: 2021-02-19
     * @Return: java.lang.String
     */
    @Override
    public String skipNoticeIndexHtml() {
        return prefix + "/notice";
    }

    /**
     * @Description: []
     * <p></P>
     * @Title: skipNoticeAddHtml
     * @Author: Lance Ting
     * @Date: 2021-02-19
     * @Param:
     * @Return: java.lang.String
     */
    @Override
    public String skipNoticeAddHtml() {
        return prefix + "/add";
    }

    /**
     * @Description: []
     * <p></P>
     * @Title: skipNoticeModifyHtml
     * @Author: Lance Ting
     * @Date: 2021-02-19
     * @Param: modelMap
     * @Param: noticeId
     * @Return: java.lang.String
     * @Throws:
     */
    @Override
    public String skipNoticeModifyHtml(ModelMap modelMap, Long noticeId) {
        SystemNotice notice = systemNoticeService.selectNoticeById(noticeId);
        modelMap.put("notice", notice);
        return prefix + "/edit";
    }

    /*
     * ================================================
     *  Rest功能实现
     * ================================================
     */

    /**
     * @Description: []
     * <p></P>
     * @Title: queryNoticeList
     * @Author: Lance Ting
     * @Date: 2021-02-19
     * @Param: notice
     * @Return: cn.supermaster.management.common.page.TableDataInfo
     */
    @Override
    public TableDataInfo queryNoticeList(SystemNotice notice) {
        WebHelper.startPage();
        List<SystemNotice> list = systemNoticeService.selectNoticeList(notice);
        return WebHelper.getDataTable(list);
    }

    /**
     * @param notice
     * @Description: []
     * <p></P>
     * @Title: addNotice
     * @Author: Lance Ting
     * @Date: 2021-02-19
     * @Param: notice
     * @Return: cn.supermaster.management.common.response.WebResult
     * @Throws:
     */
    @Override
    public WebResponse addNotice(SystemNotice notice) {
        notice.setCreateBy(ShiroUtils.getuserName());
        int rows = systemNoticeService.insertNotice(notice);
        return WebHelper.webResult(rows);
    }

    /**
     * @param notice
     * @Description: []
     * <p></P>
     * @Title: modifyNotice
     * @Author: Lance Ting
     * @Date: 2021-02-19
     * @Param: notice
     * @Return: cn.supermaster.management.common.response.WebResult
     * @Throws:
     */
    @Override
    public WebResponse modifyNotice(SystemNotice notice) {
        notice.setUpdateBy(ShiroUtils.getuserName());
        int rows = systemNoticeService.updateNotice(notice);
        return WebHelper.webResult(rows);
    }

    /**
     * @param ids
     * @Description: []
     * <p></P>
     * @Title: deleteNotices
     * @Author: Lance Ting
     * @Date: 2021-02-19
     * @Param: ids
     * @Return: cn.supermaster.management.common.response.WebResult
     */
    @Override
    public WebResponse deleteNotices(String ids) {
        int rows = systemNoticeService.deleteNoticeByIds(ids);
        return WebHelper.webResult(rows);
    }
}